package com.HomeWorkhsp.chapter13.homework;

public class Homework01 {
    public static void main(String[] args) {
        String str = "abcdef";
        System.out.println(str);
        try {
            str = reverse(str, 1, 5);
        }catch (Exception e){
            System.out.println(e.getMessage());
            return;
        }
        System.out.println("====交换后======");
        System.out.println(str);
    }

    public static String reverse(String str, int start, int end){
        if(!(str != null && start >= 0 && end < str.length() )) {
            throw new RuntimeException("参数不正确！");
        }
        char[] chars = str.toCharArray();
            for (int i = start, j = end; i < j; i++, j--) {
                char temp = chars[i];
                chars[i] = chars[j];
                chars[j] = temp;
            }
            return new String(chars);
    }
}
